//
//  RGRedPacketsView.m
//  RedGrass
//
//  Created by wukong on 2019/2/24.
//  Copyright © 2019年 hongcaosp. All rights reserved.
//  190 * 350

#import "RGRedPacketsView.h"

@interface RGRedPacketsView()

@property (strong, nonatomic) UIView *contenView1;
@property (strong, nonatomic) UIView *contenView2;

@property (strong, nonatomic) UIImageView *moneyImg;

@property (strong, nonatomic) UILabel *alertLabel1;
@property (strong, nonatomic) UILabel *alertLabel2;
@property (strong, nonatomic) UIImageView *bgImg1;
@property (strong, nonatomic) UIButton *openBtn;

@property (strong, nonatomic) UIImageView *moneyImg1;
@property (strong, nonatomic) UILabel *alertLabel3;
@property (strong, nonatomic) UILabel *alertLabel4;
@property (strong, nonatomic) UIImageView *bgImg2;
@property (strong, nonatomic) UIButton *closeBtn;


@end

@implementation RGRedPacketsView

-(instancetype)initWithFrame:(CGRect)frame{
    if(self = [super initWithFrame:frame]){
        [self addSubview:self.contenView1];
        [_contenView1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_equalTo(UIEdgeInsetsZero);
        }];
        [self initView1];
        [self initView2];
    }
    return self;
}


-(void)initView1{
    [self.contenView1 addSubview:self.bgImg1];
    [_bgImg1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.mas_equalTo(self.contenView1).mas_offset(0);
        make.top.mas_equalTo(self.contenView1).mas_offset(25);
        make.height.mas_equalTo(260);
    }];
    [self.contenView1 addSubview:self.alertLabel1];
    [_alertLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.contenView1).mas_offset(0);
        make.top.mas_equalTo(self.bgImg1.mas_top).mas_offset(10);
    }];
    [self.contenView1 addSubview:self.alertLabel2];
    [_alertLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.contenView1).mas_offset(0);
        make.top.mas_equalTo(self.alertLabel1.mas_bottom).mas_offset(-2);
    }];
    [self.contenView1 addSubview:self.moneyImg];
    [_moneyImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.contenView1).mas_offset(0);
        make.top.mas_equalTo(self.bgImg1.mas_top).mas_offset(65);
    }];
    [self.contenView1 addSubview:self.openBtn];
    [_openBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(80, 60));
        make.centerX.mas_equalTo(self.contenView1).mas_offset(0);
        make.bottom.mas_equalTo(self.bgImg1.mas_bottom).mas_offset(-30);
    }];
}

-(void)initView2{
    [self.contenView2 addSubview:self.bgImg2];
    [_bgImg2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.mas_equalTo(self.contenView2).mas_offset(0);
        make.top.mas_equalTo(self.contenView2).mas_offset(25);
        make.height.mas_equalTo(260);
    }];
    
    [_contenView2 addSubview:self.moneyImg1];
    [_moneyImg1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.contenView2).mas_offset(0);
        make.top.mas_equalTo(self.contenView2).mas_offset(0);
    }];
    
    [self.contenView2 addSubview:self.alertLabel4];
    [_alertLabel4 mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerX.mas_equalTo(self.contenView2).mas_offset(0);
        make.leading.mas_equalTo(self.contenView2).mas_equalTo(5);
        make.trailing.mas_equalTo(self.contenView2).mas_equalTo(-5);
        make.bottom.mas_equalTo(self.bgImg2.mas_bottom).mas_offset(-30);
    }];
    [self.contenView2 addSubview:self.alertLabel3];
    [_alertLabel3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.contenView2).mas_offset(0);
        make.bottom.mas_equalTo(self.alertLabel4.mas_top).mas_offset(-15);
    }];
    [self.contenView2 addSubview:self.closeBtn];
    [_closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.size.mas_equalTo(CGSizeMake(80, 60));
        make.centerX.mas_equalTo(self.contenView2).mas_offset(0);
        make.bottom.mas_equalTo(self.contenView2).mas_offset(0);
    }];
}


#pragma mark - reponse

-(void)openBtnClick:(UIButton *)button{
    if([self.viewDelegate respondsToSelector:@selector(gainRedPacketsView:)]){
        [self.viewDelegate gainRedPacketsView:self];
    }

}

-(void)closeBtnClick:(UIButton *)button{
    if([self.viewDelegate respondsToSelector:@selector(choseRedPacketsView:)]){
        [self.viewDelegate choseRedPacketsView:self];
    }
}

-(void) changeViewStyleWithIsSuccess:(BOOL)issccuess money:(NSString *)money{
    
    if(![self checkContentView2IsShow]){
        [_contenView1 removeFromSuperview];
        [self addSubview:self.contenView2];
        [_contenView2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_equalTo(UIEdgeInsetsZero);
        }];
        if(issccuess){
            self.alertLabel3.text = [NSString stringWithFormat:@"%@元",money];
            self.alertLabel4.text = @"已放入钱包，请查收";
        }else{
            self.alertLabel3.text = @"";
            self.alertLabel4.text = money;
        }
    }
}
-(BOOL) checkContentView2IsShow{
    UIView *view = _contenView2.superview;
    if(view){
        return YES;
    }
    return NO;
    
}


#pragma mark - getter

-(UIView *)contenView1{
    if(!_contenView1){
        _contenView1 = [[UIView alloc]init];
        _contenView1.backgroundColor = [UIColor clearColor];
        _contenView1.tag = 1988;
    }
    return _contenView1;
}

-(UIView *)contenView2{
    if(!_contenView2){
        _contenView2 = [[UIView alloc]init];
        _contenView2.backgroundColor = [UIColor clearColor];
        _contenView2.tag = 1999;
    }
    return _contenView2;
}

-(UILabel *)alertLabel1{
    if(!_alertLabel1){
        _alertLabel1 = [[UILabel alloc]init];
        _alertLabel1.text = @"抢到一个";
        _alertLabel1.numberOfLines = 0;
        _alertLabel1.font = FONT(customBoldName, 16);
        _alertLabel1.textColor = UICOLOR_WITH_RGBINT(0xFEFD92);
    }
    return _alertLabel1;
}

-(UILabel *)alertLabel2{
    if(!_alertLabel2){
        _alertLabel2 = [[UILabel alloc]init];
        _alertLabel2.text = @"现金大红包";
        _alertLabel2.numberOfLines = 0;
        _alertLabel2.font = FONT(customBoldName, 22);
        _alertLabel2.textColor = UICOLOR_WITH_RGBINT(0xFEFD92);
    }
    return _alertLabel2;
}

-(UIImageView *)moneyImg{
    if(!_moneyImg){
        _moneyImg = [[UIImageView alloc]init];
        _moneyImg.image = IMAGE_NAMED(@"$");
    }
    return _moneyImg;
}


-(UIImageView *)moneyImg1{
    if(!_moneyImg1){
        _moneyImg1 = [[UIImageView alloc]init];
        _moneyImg1.image = IMAGE_NAMED(@"$");
    }
    return _moneyImg1;
}

-(UIImageView *)bgImg1{
    if(!_bgImg1){
        _bgImg1 = [[UIImageView alloc]init];
        _bgImg1.image = IMAGE_NAMED(@"hongbao1");
    }
    return _bgImg1;
}


-(UIButton *)openBtn{
    if(!_openBtn){
        _openBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_openBtn setImage:IMAGE_NAMED(@"hongbao_拆") forState:UIControlStateNormal];
        [_openBtn addTarget:self action:@selector(openBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _openBtn;
}


-(UIImageView *)bgImg2{
    if(!_bgImg2){
        _bgImg2 = [[UIImageView alloc]init];
        _bgImg2.image = IMAGE_NAMED(@"hongbao2");
    }
    return _bgImg2;
}

-(UILabel *)alertLabel3{
    if(!_alertLabel3){
        _alertLabel3 = [[UILabel alloc]init];
        _alertLabel3.text = @"0.6元";
        _alertLabel3.numberOfLines = 0;
        _alertLabel3.font = FONT(customBoldName, 30);
        _alertLabel3.textColor = UICOLOR_WITH_RGBINT(0xFEFD92);
    }
    return _alertLabel3;
}

-(UILabel *)alertLabel4{
    if(!_alertLabel4){
        _alertLabel4 = [[UILabel alloc]init];
        _alertLabel4.text = @"已放入钱包，请查收";
        _alertLabel4.numberOfLines = 0;
        _alertLabel4.font = FONT(customBoldName, 16);
        _alertLabel4.textAlignment = NSTextAlignmentCenter;
        _alertLabel4.textColor = UICOLOR_WITH_RGBINT(0xFEFD92);
    }
    return _alertLabel4;
}

-(UIButton *)closeBtn{
    if(!_closeBtn){
        _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_closeBtn setImage:IMAGE_NAMED(@"关闭_红包") forState:UIControlStateNormal];
        [_closeBtn addTarget:self action:@selector(closeBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _closeBtn;
}

@end
